package de.fhkl.oic.examples.sendobjects;

import javax.jms.*;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class ConsumerB
{

    // URL of the JMS server
    private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
    // Name of the queue we will receive messages from
    private static String m_queue_name = "Consumer.B.VirtualTopic.SendObjects";

    private static ConnectionFactory m_factory;
    private Connection m_connection;
    private Session m_session;

    public ConsumerB()
    {
        // Getting JMS connection from the server
        m_factory = new ActiveMQConnectionFactory(url);
        try
        {
            m_connection = m_factory.createConnection();
            m_connection.start();

            m_session = m_connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        } catch (Exception e)
        {

        }
    }

    public static void main(String[] args) throws JMSException
    {

        ConsumerB consumer = new ConsumerB();

        Destination dest = consumer.m_session.createQueue(m_queue_name);
        MessageConsumer mescon = consumer.m_session.createConsumer(dest);
        mescon.setMessageListener(new Listener());

    }

    public Session getSession()
    {
        return this.m_session;
    }

    public void close() throws JMSException
    {
        m_connection.close();
    }

}
